package com.marquis.cloud.controller;

import com.marquis.cloud.client.AutUserClient;
import com.marquis.cloud.entity.AutUser;
import com.marquis.cloud.pagequery.PaginationGrid;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

@RestController
@Configuration
@RequestMapping("/aut/user/")
public class AutUserController {

    @Autowired
    private AutUserClient userClient;

    /**
     * 查询所有用户
     * @return
     */
    @RequestMapping(value = "queryUserPage")
    public PaginationGrid<AutUser> findAll(HttpServletRequest request, PaginationGrid<AutUser> page) {
        try {
            page = userClient.queryUserPage(page.getPage(), page.getPageSize());
            for (AutUser user : page.getRows()) {
                user.setCallerURL(request.getRequestURL().toString());
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return page;
    }

    /**
     * 根据用户名查询用户信息
     * @param userName 用户名
     * @return
     */
    @RequestMapping(value = "findByUserName")
    public AutUser findByUserName(HttpServletRequest request, String userName){
        return userClient.findByUserName(userName);
    }
}
